package cn.iocoder.yudao.module.tms.dal.mysql.companyaccountperiod;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.tms.controller.admin.companyaccountperiod.vo.CompanyAccountPeriodPageReqVO;
import cn.iocoder.yudao.module.tms.dal.dataobject.companyaccountperiod.CompanyAccountPeriodDO;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface CompanyAccountPeriodMapper extends BaseMapperX<CompanyAccountPeriodDO> {

    default PageResult<CompanyAccountPeriodDO> selectPage(CompanyAccountPeriodPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CompanyAccountPeriodDO>()
                .eqIfPresent(CompanyAccountPeriodDO::getCompanyId, reqVO.getCompanyId())
                .eqIfPresent(CompanyAccountPeriodDO::getCreditLimit, reqVO.getCreditLimit())
                .eqIfPresent(CompanyAccountPeriodDO::getCreditAlertAmount, reqVO.getCreditAlertAmount())
                .eqIfPresent(CompanyAccountPeriodDO::getCurrentCreditUsed, reqVO.getCurrentCreditUsed())
                .eqIfPresent(CompanyAccountPeriodDO::getBillingCycleDays, reqVO.getBillingCycleDays())
                .eqIfPresent(CompanyAccountPeriodDO::getBillingAlertDays, reqVO.getBillingAlertDays())
                .betweenIfPresent(CompanyAccountPeriodDO::getBillingStartDate, reqVO.getBillingStartDate())
                .betweenIfPresent(CompanyAccountPeriodDO::getBillingDueDate, reqVO.getBillingDueDate())
                .betweenIfPresent(CompanyAccountPeriodDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CompanyAccountPeriodDO::getId));
    }

    default CompanyAccountPeriodDO selectByCompanyId(Long companyId) {
        return selectOne(CompanyAccountPeriodDO::getCompanyId, companyId);
    }

}
